package com.lz.ovuola.service.assembler;

import java.util.ArrayList;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.lz.ovuola.entity.PhysiologicalDataDo;
import com.lz.ovuola.service.dto.PhysiologicalDataDto;
import com.lz.ovuola.service.dto.PhysiologicalDataListDto;
import com.lz.ovuola.util.exception.BusinessException;
import com.lz.ovuola.util.exception.msg.CommonMsgEnum;
import com.lz.ovuola.util.threadlocal.UserContextHolder;

/**
 * 包装工具
 * 
 * @author fz
 *
 */
@Deprecated
public class PhysiologicalDataListAssembler implements
		Assembler<PhysiologicalDataListDto> {

	private Logger logger = LoggerFactory
			.getLogger("PhysiologicalDataListAssembler");
	private static final PhysiologicalDataListAssembler ASSEMBLER = new PhysiologicalDataListAssembler();

	private PhysiologicalDataListAssembler() {
		super();
	}

	@Override
	public PhysiologicalDataListDto toDto(Object object) throws Exception {

		if (object instanceof List) {
			@SuppressWarnings("unchecked")
			List<PhysiologicalDataDo> dos = (List<PhysiologicalDataDo>) object;
			List<PhysiologicalDataDto> dtos = new ArrayList<PhysiologicalDataDto>(
					dos.size());
			PhysiologicalDataListDto dataListDto = new PhysiologicalDataListDto();
			for (PhysiologicalDataDo physiologicalDataDo : dos) {
				PhysiologicalDataDto physiologicalDataDto = new PhysiologicalDataDto();
				physiologicalDataDto
						.setEstimateNextStartTime(physiologicalDataDo
								.getEstimateNextStartTime());
				physiologicalDataDto
						.setEstimateOvulationTime(physiologicalDataDo
								.getEstimateOvulationTime());
				physiologicalDataDto
						.setEstimateOvulationTimeDescription(physiologicalDataDo
								.getEstimateOvulationTimeDescription());
				physiologicalDataDto.setFormula(physiologicalDataDo
						.getFormula());
				physiologicalDataDto.setPhysiologicalStage(physiologicalDataDo
						.getPhysiologicalStage());
				physiologicalDataDto
						.setPregnancyRateDescription(physiologicalDataDo
								.getPregnancyRateDescription());
				physiologicalDataDto.setWaterContent(physiologicalDataDo
						.getWaterContent());
				physiologicalDataDto.setLeedingGums(physiologicalDataDo
						.getLeedingGums());
				physiologicalDataDto.setSick(physiologicalDataDo.getSick());
				dtos.add(physiologicalDataDto);
			}
			dataListDto.setDtos(dtos);
			return dataListDto;
		} else {
			logger.error(
					"---用户id：{},List<PhysiologicalDataDo>转PhysiologicalDataListDto过程中出现异常",
					UserContextHolder.get().getUserId());
			throw new BusinessException(
					CommonMsgEnum.SERVER_INTERNAL_ERROR.getStatus(),
					CommonMsgEnum.SERVER_INTERNAL_ERROR.getMsg());
		}
	}

	public static PhysiologicalDataListAssembler getAssembler() {
		return ASSEMBLER;
	}

}
